using System;
using System.Web.Mvc;
using Web.Core.Models;
using System.Web.Helpers;
using System.Web.Routing;
using Web.Core.ModeBinders;
using System.Collections.Generic;

namespace Web.Core.BootstrapperTask
{
    public class RegisterDefaultRoute : IBootstrapperTask
    {
        private readonly RouteCollection routes;

        public RegisterDefaultRoute(): this(RouteTable.Routes)
        {
        }

        internal RegisterDefaultRoute(RouteCollection routes)
        {
            this.routes = routes;
        }

        public void Execute()
        {
            routes.IgnoreRoute("robots.txt");
            routes.IgnoreRoute("{file}.xml");
            routes.IgnoreRoute("{file}.htm");
            routes.IgnoreRoute("{file}.html");
            routes.IgnoreRoute("images/{*pathInfo}");
            routes.IgnoreRoute("javascripts/{*pathInfo}");
            routes.IgnoreRoute("stylesheets/{*pathInfo}");

            //routes.IgnoreRoute("{images}/{*pathInfo}", new { folder = "images" });
           
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
            routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(jpg|gif|jpeg|png|js|css|htm|html|htc)$" });

            routes.MapRoute("Default", "{controller}/{action}/{param}", new { controller = "Home", action = "Index", param = UrlParameter.Optional }, GetNameSpaces());

            AntiForgeryConfig.CookieName = "RequestVerificationToken";

            ModelBinders.Binders.Add(typeof(ShoppingCart), new ShoppingCartModelBinder());

        }
        private static string[] GetNameSpaces()
        {
            var list = new List<string>();
            list.Add("Web.Manage.Controllers");
            return list.ToArray();
        }
        
    }
}